/* ****************************************************************************
 * Author: 671643387
 * Date: 2015/3/16
 * ***************************************************************************/

///// 登录窗口

Ext.define("sggm.view.LoginWindow", {
    extend: "Ext.Window",
    alias: 'widget.loginWindow',
    title: "管理后台登录",
    layout: "fit",
    align: "center",
    width: 300,
    height: 160,
    resizable: false,
    draggable: false,
    closable: false,
    plain: false,
    closeAction: 'destroy',
    items: [
        {
            //id: "loginForm",
            xtype: "form",
            buttonAlign: 'center',
            frame: false,
            plain: true,
            defaultType: "textfield",
            border: false,
            bodyStyle: 'padding-top:15px;',
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 70,
                allowBlank: false,
                msgTarget: "qtip",
                blankText: "必填！"
            },
            items: [{
                name: "account",
                fieldLabel: "用户名",
                labelSeparator: "：",
                value: sggm.utils.Cookie.get("authGM") || ""
            }, {
                name: "pass",
                fieldLabel: "密码",
                labelSeparator: "：",
                inputType: "password",
                allowBlank: false,
                listeners: {specialkey: function(f,e){
                     if (e.getKey() == e.ENTER) {
                        var loginWin = f.up('window');
                        var formPanel = loginWin.down("form");
                         if (formPanel.getForm().isValid()){
                            loginWin.onLogin(loginWin, formPanel);
                        }
                    }
                }}
            }],
            buttons: [{
                text: "重置",
                handler:function(sender){
                    var loginWin = sender.up("window");
                    loginWin.down("form").getForm().reset();
                }
            }, {
                text: "登录",
                handler:function(sender){ // 登录按钮处理
                    var loginWin = sender.up("window");
                    var formPanel = loginWin.down("form");
                    if (formPanel.getForm().isValid()){
                        loginWin.onLogin(loginWin, formPanel);
                    }
                }
            }]
        }
    ],

    config: {
        onLogin: null       // 登录回调
    },

    constructor: function (config) {
        var me = this;
        if (config) {
            if (config.hasOwnProperty("onLogin")
                && typeof config["onLogin"] == "function") {
                me.setOnLogin(config["onLogin"]);
            }
        }

        me.onLogin = me.onLogin || function(){};

        me.callParent(arguments);
    }
});
